<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<c:url value="/resources/css/item.css"/>" >
<style type="text/css">
	.error {
	  color: red;
	 }
</style>
</head>

<body>
<form:form modelAttribute="count" method="POST" action="">
<form:hidden path="productId" />
<div>
 <div class="top">
 <h1><c:out value="${product.name}" /></h1>
 </div>
  <div class="halves">
   <div class="leftHalf">
   <img src="<c:url value="/resources/${product.image}"/>" alt="${product.name}" style="width:200px;height:200px">
   <p> Rating: <c:out value="${mark}" />/5 (<c:out value="${voters}" />)</p>
   <c:if test="${!hideRate}">
	 <c:url var="rateUrl" value="/products/rate" >
	 	<c:param name="itemId" value="${product.productId}" />
	 </c:url>
	 	<a href='<c:out value="${rateUrl}"/>'>rate</a>
	</c:if>
  </div>
  <div class="rightHalf">
  <fmt:formatNumber value="${product.actualPrice/100}"  var="priceString" type="currency" currencySymbol="$"/>
  <p> <c:out value="${product.name}" /> price: <c:out value="${priceString}" /> </p>
  <td>In your cart: <form:input path="count" size="10"/></td> <td width="70"><input type="submit" value="add" /></td>
  <form:errors path="count" cssClass="error"/>
  <form:errors path="" cssClass="error"/>
  <p>Description: <c:out value="${product.description}" /></p>
  </div>
 </div>
 <div class="footer">
 <p></p>
 <c:forEach var="rating" items="${product.ratings}" varStatus="status">
 	<p> rated: <c:out value="${rating.mark}"/>  <c:out value="${rating.reviewText}"/></p>
 </c:forEach>
<c:if test="${lastPageNum>1}">
<c:forEach var="i" begin="1" end="${lastPageNum}" varStatus="status">
	<c:url var="pageUrl" value="/products/view" >
 		<c:param name="itemId" value="${product.productId}" />
 		<c:param name="pageNum" value= "${i}" />
    </c:url>
    	<td><a href='<c:out value="${pageUrl}"/>'>${i}</a></td>	
</c:forEach>
</c:if>

 </div> 
</div>
</form:form>

</body>
</html>